package cheme.ProcessEditor.Policies;

import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.XYLayoutEditPolicy;
import org.eclipse.gef.requests.CreateRequest;
import org.eclipse.gef.Request;

import cheme.ProcessModel.ProcessModel;
import cheme.ProcessModel.SimpleLogger;
import cheme.ProcessModel.Cmds.ContentModelCommand;
import cheme.ProcessModel.Cmds.ContentsModelChangeConstraintCmd;

public class ContentsModelPolicy extends XYLayoutEditPolicy
{
	private static String me = "cheme.ProcessEditor.Policies.ContentsModelPolicy";
	
	protected Command createAddCommand(EditPart child, Object constraint)
	{
		SimpleLogger.log(me, me + ".createAddCommand(child, constraint)");
		
		return null;
	}

	protected Command createChangeConstraintCommand(EditPart child,
			Object constraint)
	{
		SimpleLogger.log(me, me
				+ ".createChangeConstraintCommand(child, constraint)");
		
		ContentsModelChangeConstraintCmd command = new ContentsModelChangeConstraintCmd();

		command.setModel(child.getModel());
		command.setConstraint((Rectangle) constraint);

		return command;
	}

	protected Command getCreateCommand(CreateRequest request)
	{
		SimpleLogger.log(me, me + ".getCreateCommand(request)");
		
		ContentModelCommand command = new ContentModelCommand();

		Rectangle constraint = (Rectangle) getConstraintFor(request);

		/*
		 * Wow, how is it that the request has an newly created model object for 
		 * me?
		 */
		ProcessModel model = (ProcessModel) request.getNewObject();

		model.setConstraint(constraint);

		command.setContentsModel(getHost().getModel());
		command.setHelloModel(model);
		return command;
	}

	protected Command getDeleteDependantCommand(Request request)
	{
		SimpleLogger.log(me, me + ".getDeleteDependantCommand(request)");
		
		return null;
	}

}
